﻿using HtmlAgilityPack;
using Spider.Analyse;
using Spider.Entitys.天气预报各级实体对象;
using Spider.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spider.HTMLAnalyse.天气预报各级HTML解析
{
    public class 天气预报市解析 : AnalyseBase, IAnalyse
    {
        public override List<T> GetListData<T>(HtmlDocument doc, IRule rule, object o = null)
        {
            List<T> listEntity = new List<T>();
            //更加xpath获取总的对象，如果不为空，就继续选择dl标签
            HtmlNode res = doc.DocumentNode.SelectSingleNode(rule.RuleXPathString());
            if (res != null)
            {
                var list = res.SelectNodes(@"dl");//选择标签数组
                foreach (var item in list)
                {
                    var ddlist = item.SelectNodes(@"dd");
                    var aNodeList = ddlist[0].SelectNodes("a");
                    foreach (var a in aNodeList)
                    {
                        天气预报市 entity = new 天气预报市()
                        {
                            URL = a.OuterHtml.GetHref(),
                            市名称 = a.InnerText
                        };
                        listEntity.Add((T)(object)entity);
                    }
                }
            }
            return listEntity;
        }
    }
}
